package com.itheima.controller;

import com.itheima.common.Com.Setmeal;
import com.itheima.common.pojo.PageInfo;
import com.itheima.common.pojo.Result;
import com.itheima.common.vo.SetmealVo;
import com.itheima.service.SetmealService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 86188
 */
@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Autowired
    private SetmealService setmealService;

    @GetMapping("/{id}")
    public Result getById(@PathVariable("id") String id) {

        SetmealVo byId = setmealService.getById(id);

        return Result.success("成功", byId);
    }

    @GetMapping("page")
    public Result page(@Param("name") String name, @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        PageInfo<Setmeal> page1 = setmealService.page(name, page, pageSize);
        return Result.success("查询成功", page1);

    }

    @PostMapping
    public Result save(@RequestBody SetmealVo setmealVo) {

        setmealService.save(setmealVo);
        return Result.success("成功");
    }

    @PutMapping
    public Result update(@RequestBody SetmealVo setmealVo) {
        setmealService.update(setmealVo);
        return Result.success("成功");
    }

    @DeleteMapping
    public Result delete(@RequestParam("ids") String ids) {
        boolean delete = setmealService.delete(ids);
        return Result.success("成功", delete);
    }

    @PostMapping("/status/{status}")
    public Result stop(@PathVariable Integer status, @RequestParam("ids") String ids) {
        setmealService.stop(status, ids);
        return Result.success("成功");

    }
}
